package cn.jm.study.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class DirList {

	public List<File> getDirList() {
		List<File> result = new ArrayList<File>();
		File path = new File("D:\\工作文档\\资料");
		File [] list = path.listFiles();
		for(File item:list) {
			
			if(getExtName(item.getName()).equals("docx")) {
				result.add(item);
			};
		}
		
		return result;
	}
	
	
	public String getExtName(String name) {
		int post  = name.lastIndexOf(".")+1;
		return name.substring(post,name.length()).toLowerCase();
	}
	
	public void makeDirectory() {
		String dirName = "d:\\shaoming\\shao\\ming\\shao";
		File directory = new File(dirName);
		
		if(! directory.exists()) {
			directory.mkdirs();
		}
	}

	public void writeTextFile(String fileName) {
		try {
			PrintWriter write = new PrintWriter(new File(fileName));
			write.append("邵明cssdfasdf adf");
			write.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
